<?php

	/**
	 * Elgg read blog post page
	 * 
	 * @package ElggBlog
	 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
	 * @author Curverider Ltd <info@elgg.com>
	 * @copyright Curverider Ltd 2008
	 * @link http://elgg.com/
	 */

	// Load Elgg engine
		require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");

		// Get configuration settings
		$config = find_plugin_settings('treecategories');
		$cats = json_decode($config->categories, true);

	// Get the specified blog post
		$cat = get_input('category');

		if(strlen($cat) == 2) {
			$supCat = substr($cat, 0, 1);
			$subCat = substr($cat, 1, 1);

			// If we can get out the blog post ...
			if ($blogposts = list_entities_from_metadata("category", $cat)) {
			
				$area2 = elgg_view_title(elgg_echo('category').' : '.$cats['categories']['main'][$supCat]['sub'][$subCat]['value']);
				// Get a list of blog posts
				$area2 .= $blogposts;

				// Display them in the page
			  $body = elgg_view_layout("two_column_left_sidebar", '', $area1 . $area2);

			// If we're not allowed to see the blog post
			} else {
		// Display the 'post not found' page instead
				$body = elgg_view("blog/notfound");
				$title = elgg_echo("blog:notfound");
			}
		}
		elseif(strlen($cat) == 1) {
			// If we can get out the blog post ...
			if ($blogposts = list_entities_from_metadata('supCat', $cat)) {

				$area2 = elgg_view_title(elgg_echo('category').' : '.$cats['categories']['main'][$cat]['value']);
				// Get a list of blog posts
				$area2 .= $blogposts;

				// Display them in the page
			  $body = elgg_view_layout("two_column_left_sidebar", '', $area1 . $area2);

			// If we're not allowed to see the blog post
			} else {
		// Display the 'post not found' page instead
				$body = elgg_view("blog/notfound");
				$title = elgg_echo("blog:notfound");
			}
			
		}
		
	// Display page
		page_draw(elgg_echo('blog:categories'),$body);
		
?>